package scjp.preparation.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileReaderTest {

	/**
	 * @param args
	 */
	public static void main(String[] files) {
		if (files.length != 2) {
			System.out.println("pass the name of file(s) as ragument");
			System.exit(-1);
		}

		String srcFile = files[0];
		String dstFile = files[1];

		// try {
		// int c = 0;
		// FileReader inputFile = new FileReader(fileName);
		// if(inputFile != null) {
		// while((c = inputFile.read()) != -1) {
		// System.out.println((char)c);
		// }
		// }
		// } catch (FileNotFoundException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (IOException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		try (BufferedReader inputFile = new BufferedReader(new FileReader(
				srcFile));
				BufferedWriter outputFile = new BufferedWriter(new FileWriter(
						dstFile))) {
			int c = 0;
			while ((c = inputFile.read()) != -1) {
				outputFile.write((char) c);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

	}

}
